package com.nami.ucenter.infra.core.middleware.mq.producer;

import com.nami.gate.external.basic.constants.UpdCacheTopicConst;
import com.nami.gate.external.basic.event.EventPublisher;
import com.nami.gate.external.basic.event.model.CommonEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RequiredArgsConstructor
public class UCenterEventPublisher implements EventPublisher {

    private final RocketMQTemplate rocketMQTemplate;

    @Override
    public void publish(CommonEvent event) {
        try {
            switch (event.getEventType()) {
                case REFRESH_L1_USER_CACHE:
                    rocketMQTemplate.syncSend(UpdCacheTopicConst.REFRESH_USER_TOPIC, event.getPayload());
                    break;
                default:
                    log.error("[USER] 未匹配类型：{}", event.getEventType());
                    break;
            }
        } catch (Exception var2) {
            var2.printStackTrace();
            log.error("[USER-publisher] publish出现问题：", var2);
        }
    }

}
